//let arr1 = [7,9,3,6];
//let arr2 = [{key:12,name:'你的'},{key:7,name:'我的'},{key:3,name:'他的'},{key:9,name:'她的'},{key:5,name:'它的'},{key:6,name:'ta的'}];
//return [{key:7,name:'我的'},{key:3,name:'他的'},{key:9,name:'她的'},{key:6,name:'ta的'}]
//根据指定字段过滤数组
/* export function filterArr(arr1,arr2,key){
	return arr1.map(item =>{
		return arr2.find(arr=>{
			return arr[key] == item;
		})；
	})；
}; */

//数组去重
export function uniqueArr(arr) {
  return Array.from(new Set(arr))
}

//对象合并
export function objectMerge(target, source) {
  /* Merges two  objects,
     giving the last one precedence */

  if (typeof target !== 'object') {
    target = {}
  }
  if (Array.isArray(source)) {
    return source.slice()
  }
  Object.keys(source).forEach(property => {
    const sourceProperty = source[property]
    if (typeof sourceProperty === 'object') {
      target[property] = objectMerge(target[property], sourceProperty)
    } else {
      target[property] = sourceProperty
    }
  })
  return target
}

//html转文本
export function html2Text(val) {
  const div = document.createElement('div')
  div.innerHTML = val
  return div.textContent || div.innerText
}

//url提取参数为一个json对象
export function param2Obj(url) {
  const search = url.split('?')[1]
  if (!search) {
    return {}
  }
  return JSON.parse(
    '{"' +
      decodeURIComponent(search)
        .replace(/"/g, '\\"')
        .replace(/&/g, '","')
        .replace(/=/g, '":"') +
      '"}'
  )
}
//字符串去首尾空格
export function trim(string) {
  return (string || '').replace(/^[\s\uFEFF]+|[\s\uFEFF]+$/g, '');
};